package com.fengmi.mapper;

import com.fengmi.entity.SysPermissionEntity;
import com.fengmi.entity.SysRoleEntity;
import com.fengmi.entity.SysUserEntity;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 存储库：用户信息表
 *
 * @author
 * @date 2022-02-09 19:58:02
 */
@Repository
public interface SysUsermapper {
    //根据前端用户名查询用户信息
    @Select("select * from sys_user where user_name = #{userName}")
    SysUserEntity findUserByUserName(String userName);

    //根据用户ID查询用户角色信息
    @Select("select sr.* from sys_user su\n" +
            "    left join sys_user_role sur on su.user_id = sur.user_id\n" +
            "    left join sys_role sr on sr.role_code = sur.role_id\n" +
            "    where su.user_id = #{userId}")
    List<SysRoleEntity> findRoleByUserId(String userId);

    //根据用用户id查询角色权限
    @Select("select sp.* from sys_user su\n" +
            "    left join sys_user_role sur on su.user_id = sur.user_id\n" +
            "    left join sys_role sr on sr.role_code = sur.role_id\n" +
            "    left join sys_role_permission srp on sur.role_id = srp.role_id\n" +
            "    left join sys_permission sp on sp.perm_code = srp.perm_id\n" +
            "    where su.user_id = #{userId}")
    List<SysPermissionEntity> findPermssionByUserId(String userId);
}